<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // 传统面向对象 es6继承
        class MovieCollection extends Array {
            constructor(name, ...items) { // reset
                super(...items); // 调用父类的构造函数 展开运算符
                this.name = name;
            }
            add(movie) {
                this.push(movie);
            }
            topRate(limit = 5) { // 默认值
                return this.sort((a, b) => a.stars - b.stars).slice(0, limit);
            }
        }

        const movies = new MovieCollection('Wes\'s Fav Movies',
            { name: '10s', stars: 10 },
            { name: '11s', stars: 11 },
            { name: '12s', stars: 12 },
            { name: '13s', stars: 13 },
        )
        movies.add({ name: 'yellow star', stars: 9 });
        movies.add({ name: 'yellow', stars: 19 });
        console.log(movies.topRate());
        const test = [
            { name: '10s', stars: 10 },
            { name: '11s', stars: 11 },
            { name: '12s', stars: 12 },
            { name: '13s', stars: 13 }
        ]
        console.log('...test',...test);
        /**
         * ...test {name: '10s', stars: 10} {name: '11s', stars: 11} {name: '12s', stars: 12} {name: '13s', stars: 13}
        */
    </script>
</body>

</html>